<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class Store extends Model
{
    //
	use Notifiable;
	protected $table='store';
	protected $fillable=['department_id','name','owner_name','leader_id','people_num','month_hour','continue_hour','radius'
		,'longitude','latitude','address','company_id'];
	protected $hidden=['remember_token'];


	public function lists($where){
//		return $where;
		$data= $this->where(function ($query) use($where){
			$query->where(['company_id'=>$where['company_id']]);
			if($where['name'] !=null){
				$query->where('name','like','%'.$where['name'].'%');
			}
			if($where['owner_name'] !=null){
				$query->where('owner_name','like','%'.$where['owner_name'].'%');
			}
			if($where['address'] !=null){
				$query->where('address','like','%'.$where['address'].'%');
			}
			if($where['start_time'] !=null){
				$query->where('created_at','>',$where['start_time']);
			}
			if($where['end_time'] !=null){
				$query->where('created_at','<',$where['end_time']);
			}
			if($where['status'] !=null){
				$query->where(['status'=>$where['status']]);
			}

		})->with('configuration_status')->paginate(config('app.config'));

//		foreach ($data as $kk=>$vv){
//			$data[$kk]['status']=$vv['status']?'有效':'失效';
//		}
		return $data;
	}


//	查询店铺的详细信息
	public function store_desc($id){
		return $this->where(['id'=>$id])->first();
	}


//	查询该店铺下的所有员工
	public function all_staff(){

	}

//	根据部门查询店铺id
	public function department($department_id){
		return $this->where(['department_id'=>$department_id])->first();
	}
//	获取该公司下所有的店铺
	public function all_depart($company_id){
		return $this->where(['company_id'=>$company_id,'status'=>1])->select('id','name')->get();
	}


	public function configuration_status(){
		return $this->hasOne('App\Model\Configuration_status','configuration_id','status');
	}


}
